﻿namespace Falcon.Forums.Domain
{
	using Falcon.Core.Domain;
	using Falcon.Forums.Domain.Enums;

	public class ForumTopicSubscription : EntityBase<ForumTopicSubscription>
	{
		// private fields
		private ForumTopic _topic;
		private User _user;

		/// <summary>
		/// Initializes a new instance of the <see cref="ForumTopicSubscription"/> class.
		/// </summary>
		public ForumTopicSubscription()
		{
			base.DeterminePermission(Roles.ForumsTopicsSubscriptions);
		}

		/// <summary>
		/// Gets or sets the topic id.
		/// </summary>
		/// <value>The topic id.</value>
		public virtual int TopicId
		{
			get; 
			set;
		}

		/// <summary>
		/// Gets or sets the user id.
		/// </summary>
		/// <value>The user id.</value>
		public virtual int UserId
		{
			get; 
			set;
		}

		/// <summary>
		/// Gets or sets the notification.
		/// </summary>
		/// <value>The notification.</value>
		public virtual ForumTopicSubscriptionNotification Notification
		{
			get; 
			set;
		}

		/// <summary>
		/// Gets or sets the topic.
		/// </summary>
		/// <value>The topic.</value>
		public virtual ForumTopic Topic
		{
			get
			{
				return _topic;
			}
			set
			{
				_topic = value;

				if (_topic != null)
				{
					this.TopicId = _topic.Id;
				}
			}
		}

		/// <summary>
		/// Gets or sets the user.
		/// </summary>
		/// <value>The user.</value>
		public virtual User User
		{
			get
			{
				return _user;
			}
			set
			{
				_user = value;

				if (_user != null)
				{
					this.UserId = _user.Id;
				}
			}
		}

		/// <summary>
		/// Validates this instance.
		/// </summary>
		public override void Validate()
		{
			this.Rules().Validate(this);
		}
	}
}